﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Robotics
{
	class ParallelActivityManager : Activity
	{
		private LinkedList< Activity > startingActivities = new LinkedList<Activity>();
		private LinkedList< Activity > activities = new LinkedList<Activity>();
		private LinkedList< Activity > endingActivities = new LinkedList<Activity>();

		public bool Tick()
		{
			foreach ( Activity activity in startingActivities )
			{
				activity.Start();
				activities.AddLast( activity );
			}
			startingActivities.Clear();
			foreach ( Activity activity in activities )
			{
				if ( !activity.Tick() )
					endingActivities.AddLast( activity );
			}
			foreach ( Activity activity in endingActivities )
			{
				activity.End();
			}
			endingActivities.Clear();
			return true;
		}

		public void Add( Activity activity )
		{
			startingActivities.AddLast( activity );
		}
	}
}
